package com.ibm.law.ui;

import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import swing2swt.layout.BorderLayout;

import com.ibm.law.data.CachedData;
import com.ibm.law.ui.system.action.InitializeAction;

public class AppWindow extends ApplicationWindow {
	public static ApplicationWindow window;

	/**
	 * Create the application window.
	 */
	public AppWindow() {
		super(null);
		createActions();
		addToolBar(SWT.FLAT | SWT.WRAP);
		addMenuBar();
		addStatusLine();
	}

	/**
	 * Create contents of the application window.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createContents(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new BorderLayout(0, 0));
		{
			// Tree tree = new Tree(container, SWT.BORDER);
			MenuTreeViewer treeViewer = new MenuTreeViewer(container);
			treeViewer.setInput("Root");
			
			treeViewer.getTree().setSize(500,0);
			treeViewer.getTree().setLayoutData(BorderLayout.WEST);
			treeViewer.getTree().setVisible(true);
		}

		return container;
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
	
	}

	/**
	 * Create the menu manager.
	 * 
	 * @return the menu manager
	 */
	@Override
	protected MenuManager createMenuManager() {
		return MenuManagerFactory.createMenuManager();
	}

	/**
	 * Create the toolbar manager.
	 * 
	 * @return the toolbar manager
	 */
	@Override
	protected ToolBarManager createToolBarManager(int style) {
		ToolBarManager toolBarManager = new ToolBarManager(style);
		return toolBarManager;
	}

	/**
	 * Create the status line manager.
	 * 
	 * @return the status line manager
	 */
	@Override
	protected StatusLineManager createStatusLineManager() {
		StatusLineManager statusLineManager = new StatusLineManager();
		return statusLineManager;
	}

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static ApplicationWindow getInstance() {
		if (window == null) {
			window = new AppWindow();
		}
		return window;
	}

	public static void main(String args[]) {
		try {
			CachedData.init();
			final Display display = Display.getDefault();
			Realm.runWithDefault(SWTObservables.getRealm(display),
					new Runnable() {
						public void run() {
							ApplicationWindow window = getInstance();
							window.setBlockOnOpen(true);
							window.open();
							Display.getCurrent().dispose();
						}
					});

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Configure the shell.
	 * 
	 * @param newShell
	 */
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setMaximized(true);
		newShell.setText("司法鉴定");
	}

	/**
	 * Return the initial size of the window.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(450, 300);
	}

}
